<!--
* description: 网点对应仓库维护-编辑
-->
<template>
  <section class="editBigAreaInfo">
    <el-dialog
      v-dialogDrag
      :close-on-click-modal="false"
      :title="textMap[popupsState]"
      :append-to-body="true"
      :visible.sync="curPopupsVisible"
      width="70%"
      @close="closeEdit"
    >
      <dialogHeader
        slot="title"
        :title="textMap[popupsState]"
        :style-type="$store.state.app.dialogType"
      />

      <div class="filter-container filter-params">
        <el-row ref="vailComponentList" :gutter="26">
          <component
            :is="comp.component"
            v-for="comp in tableComponents.filter(o => o.isMust === true)"
            :ref=" comp.isRequire ? comp.isRequire + comp.compKey : comp.compKey"
            :key="comp.compKey"
            :validrule="comp.validrule"
            :code-field="comp.codeField"
            :text-field="comp.textField"
            :popups-key="comp.compKey"
            :parent-fileds="comp.parentFileds"
            :code="formField[comp.codeField]"
            :text="formField[comp.textField]"
            :disabled="comp.disabled"
            :o-fields="comp.oFields"
            :options="comp.options"
            :show-placeholder="comp.placeholder"
            :custom-obj="comp.customObj"
            :is-require="comp.isRequire"
            :is-mul="comp.isMul"
            :span="comp.span || 24"
            :label-name="comp.labelName"
            :lookuptype="comp.lookuptype"
            :data-to-object="comp.dataToObject"
            :date-options-type="comp.dateOptionsType"
            @changeCode="getComponentCode"
            @focusCode="getFocusCode"
          />
        </el-row>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button
          v-for="comp in tableButtons"
          :key="comp.compKey"
          :type="comp.type"
          :icon="comp.icon"
          @click="comp.clickEvent"
        >{{ comp.text }}</el-button>
      </div>
    </el-dialog>
  </section>
</template>
<script>
import { formMixins } from '@/components/mixins/formMixins'
import { orgApis } from "@/api/paSparePartsManagement"

export default {
  components: {
    dialogHeader: () => import('@/components/dialogHeader'),
    mixButton: () => import('@/components/basicComponent/mixButton')
  },

  // 组件混入对象
  mixins: [formMixins],

  props: {
    popupsVisible: { type: Boolean, default: false },
    // 从网格传入的编辑行数据(json)
    dynamicEditRowData: { type: Object, default: function() { return {} } },
    editRowData: { type: Object, default: false }
  },

  data() {
    const viewPageCode = 'bigAreaInfo-edit'
    return {
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey1',
          type: 'primary',
          size: 'small',
          icon: 'iconfont  icon-preservation',
          clickEvent: () => this.editSave(),
          // text: this.$t('sys.button.save') /* 保存*/,
          text: '保存',
          position: 'right'
        },
        {
          compKey: 'btnKey2',
          type: '',
          size: 'small',
          icon: 'iconfont  icon-cancel',
          clickEvent: () => this.closeEdit(),
          text: this.$t('sys.button.cancel') // 取消
        }
      ],

      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode] &&
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode].formComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[viewPageCode].formComponents
          : [
            {
              compKey: 'comKey1',
              labelName: '网点编码：',
              codeField: 'dlrShortName',
              textField: 'dlrCode',
              component: () => import('@/views/ve/planReport/components/multipleSearchInput'),
              type: 'inputText',
              isMust: true,
              isRequire: true,
              dataToObject: {
                // 控制弹窗页面 搜索 网格 元素
                tableComponents: [
                  {
                    compKey: "compKey1",
                    labelName: "网点编码：",
                    codeField: "dlrCode",
                    component: () => import("@/components/org/commonInput"),
                    type: "inputText",
                    isMust: true,
                    span: 8,
                  },
                  {
                    compKey: "compKey2",
                    labelName: "网点名称：",
                    codeField: "dlrShortName",
                    component: () => import("@/components/org/commonInput"),
                    type: "inputText",
                    isMust: true,
                    span: 8,
                  },
                ],
                tableCols: [
                  {
                    prop: "dlrCode",
                    label: "网点编码",
                  },
                  {
                    prop: "dlrShortName",
                    label: "网点名称",
                  },
                ],
                formField: {
                  dlrShortName: '',
                  dlrCode: ''
                },
                oFields: 'dlrShortName,dlrCode',
                returnField: {
                  prop: "dlrCode",
                  label: "网点编码",
                },
                api: orgApis.queryOrgDlrCodes
              },
              span: 8
            },
             {
              compKey: 'compKey2',
              labelName: '网点名称',
              codeField: 'dlrShortName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true,
              disabled: true,
              span: 8
            },
            {
              compKey: 'compKey3',
              labelName: '仓库编码',
              codeField: 'warehouseCode',
              // textField: 'warehouseName',
              // oFields: 'warehouseName,warehouseCode',
              customObj: {
                api: orgApis.queryWareHouseNames,
                defOptionFields:['warehouseName','warehouseCode'],
                // listQuery: {
                //   warehouseName: '',
                //   // warehouseCode:''
                // }
              },
              component: () => import("@/components/org/commonSelect"),
              type: 'inputText',
              isMust: true,
              span: 8
            },
            {
              compKey: 'compKey4',
              labelName: '仓库名称',
              codeField: 'warehouseName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true,
              span: 8
            },
            {
              compKey: 'compKey5',
              labelName: '状态',
              codeField: 'isEnable',
              component: () => import('@/components/org/LookupValue'),
              type: 'dropdownList',
              oFields: 'isEnable,statusText',
              options: [
                { isEnable: '1', statusText: '启用' },
                { isEnable: '0', statusText: '禁用' }
              ],
              isMul: false,
              span: 8,
              isMust: true
            },
            {
              compKey: 'compKey6',
              labelName: '备注：',
              codeField: 'remark',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true,
              span: 8
            }
          ],

      // 标题
      textMap: {
        edit: '网点对应仓库编辑',
        add: '网点对应仓库新增'
      },

      // 表单数据（无需赋值，由混入对象赋值）
      formField: this.$utils.getFormField(this, {
        dlrAndWarehouseId: '',
        dlrCode: '',
        warehouseName: '',
        dlrShortName: '',
        warehouseCode: '',
        isEnable: '',
        remark: '',
        updateControlId: ''
      }, this.$ConfigCache.CacheConfig.cacheData[viewPageCode])
    }
  },

  methods: {
    // open() {
    //   // console.log( this.curPopupsVisible,'111');
    //   this.formField = this.editRowData
    //   this.formField.updateControlId = this.editRowData.updateControlId
    // },
    // 关闭弹窗
    // handleClose(done) {
    //   // this.$confirm('还未保存，确认关闭窗口？')
    //     // .then(_ => {
    //       this.$emit('update:curPopupsVisible', false)
    //       done()
    //     // })
    //     // .catch(_ => {})
    // },
    closeEdit() {
      this.curPopupsVisible = false
      this.$emit('close', false)
    },   
    // 新增/编辑保存按钮
    // save() {
    //   const that = this
    //   this.$utils.validataMoth(this, 'validpopup')
    //   if (this.valid) {
    //     if (that.popupsState === 'edit') {
    //       that.editSave()
    //     } else {
    //       that.addSave()
    //     }
    //   }
    // },

    // 编辑保存
    editSave() {
      const that = this
      // this.formField.WarehouseId = this.editRowData.WarehouseId
      const queryObj = {
        // 保存mutation
        type: 'mutation',
        // api配置
        apiConfig: orgApis.orderManagementEdit,
        // 条件/实体参数（变量），根据typeParam中的定义配置
        variables: that.formField
      }
      // 转换了中台请求格式数据
      var paramD = this.$getParams(queryObj)
      // 调用中台API方法（可复用）
      this.$requestAPI(paramD).then(response => {
        if (response.result === '1') {
          this.$message({
            message: this.$t('sys.tips.esTip5') /* 保存成功*/,
            type: 'success',
            duration: 1000
          })
          this.curPopupsVisible = false
          this.$nextTick(() => {
            this.$parent.queryTable(1)
          })
        } else {
          // 保存失败
          this.$message({
            message:
              '保存失败:' + response.msg,
            type: 'warn',
            uration: 1000
          })
        }
        this.curPopupsVisible = false
      })
    },

    // 新增保存
    // addSave() {
    //   const that = this
    //   const queryObj = {
    //     // 保存mutation
    //     type: 'mutation',
    //     // api配置
    //     apiConfig: {
    //       ServiceCode: 'addBigArea',
    //       APIUrl: '/mp/e3sh/basics/ve/bigareaService/addBigArea.do'
    //     },
    //     // 条件/实体参数（变量），根据typeParam中的定义配置
    //     variables: that.formField
    //   }
    //   // 转换了中台请求格式数据
    //   var paramD = this.$getParams(queryObj)
    //   // 调用中台API方法（可复用）
    //   this.$requestAPI(paramD).then(response => {
    //     if (response.result === '1') {
    //       this.$message({
    //         message: '添加成功',
    //         type: 'success',
    //         duration: 1000
    //       })
    //       this.curPopupsVisible = false
    //       this.$nextTick(() => {
    //         this.$parent.queryTable(1)
    //       })
    //     } else {
    //       // 保存失败
    //       this.$message({
    //         message:
    //           '添加失败:' + response.msg,
    //         type: 'warn',
    //         uration: 1000
    //       })
    //     }
    //     this.curPopupsVisible = false
    //   })
    // }
  },
  
  
}
</script>

<style lang="scss" scoped>
.promptSpan{
  position: absolute;
  bottom: 26px;
  right: 335px;
  color: #e70020;
}
// .el-dialog__wrapper {
//   /deep/ .el-dialog {
//     height: 70%;
//   }
// }


</style>

